package cn.kgc.ssm.controller;

import cn.kgc.ssm.annotations.Logs;
import cn.kgc.ssm.entity.Member;
import cn.kgc.ssm.enums.Operation;
import cn.kgc.ssm.service.MemberService;
import cn.kgc.ssm.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author 课工场
 * @date 2024/3/8
 * @description
 */
@RestController
@RequestMapping("member")
public class MemberController {

    @Resource
    private MemberService memberService;

    //会员注册
    @PostMapping("register")
    public ResponseResult  register(Member member){
        return   memberService.register(member);
    }

    //会员登录
    @PostMapping("login")
    public ResponseResult login(String memberName,String password,HttpSession session){
        return   memberService.login(memberName,password,session);
    }


    // 分页查询
    @GetMapping("page")
    @Logs(description = Operation.SELECT,model = "会员模块")
    public ResponseResult memberPage(Integer page,Integer limit,String memberName){
        return   memberService.memberPage(page,limit,memberName);
    }


    // 根据会员名查询会员信息
    @GetMapping("getByName")
    public ResponseResult  getMemberByName(String  name){
        return   memberService.getMemberByName(name);
    }


    // 添加会员
    @PostMapping("add")
    @Logs(description = Operation.ADD,model = "会员模块")
    public ResponseResult  addMember(Member member){
        return   memberService.addMember(member);
    }

    // 编辑会员
    @PostMapping("edit")
    @Logs(description = Operation.UPDATE,model = "会员模块")
    public ResponseResult  editMember(Member member){
        return   memberService.editMember(member);
    }

    // 删除会员
    @GetMapping("delete")
    @Logs(description = Operation.DELETE,model = "会员模块")
    public ResponseResult  deleteMember(Integer[] ids){
        return   memberService.deleteMember(ids);
    }

    // 重置会员的密码
    @GetMapping("reset")
    @Logs(description = Operation.UPDATE,model = "会员模块")
    public ResponseResult  resetPwd(Integer id){
        return   memberService.resetPwd(id);
    }

}
